<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<script>var ctx="${ctx}";</script>
<div class="form-horizontal" role="form" >
    <input id="id" value="${merchant.id}"  type="hidden"/>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">商家名称:</label>
        <div class="col-md-9">
        	 <input id="name" value="${merchant.name}" data-check="require:true;code:^[a-zA-Z0-9\u4e00-\u9fa5]{1,30};message:不能为空" type="text" placeholder="商家名称" class="form-control" name="name"/>
        </div>
    </div>
   	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">logo:</label>
        <div class="col-md-9">
        	 <div class="col-md-10">
	        	 <input class="fileInput" id="imageUploadify" type="file" name="file"  accept="image/*"/>
	        	 <div class="imageUploadify" id="logodiv">   
					<c:if test="${not empty(merchant.logo)}">
						<img src="${merchant.logo}" style="width: 60px;height: 60px">
					</c:if>
				 </div>
	        </div>
        </div>
      </div>
      <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">商家资质:</label>
        <div class="col-md-9">
        	 <div class="col-md-10">
	        	 <input class="fileInput" id="licenseUploadify" type="file" name="file"  accept="image/*"/>
	        	 <div class="imageUploadify" id="licensediv">   
					<c:if test="${not empty(merchant.license)}">
					<c:forEach items="${fn:split(merchant.license,',')}" var="i">
					    <div  style="width: 60px;float: left; margin-right: 5px;position: relative;" class="twoimgs"  onmouseout="javascript:$(this).find('.delimg').css('display','none')" onmousemove="javascript:$(this).find('.delimg').css('display','block')">
					          <img style=" height: 60px; width: 60px; " class="upimg" src="${i}">
					          <img style="width: 60px;position: absolute;top: 42px;display: none" class="delimg" src="${ctx}/static/img/picdel.png" onclick="javascript:$(this).parent().remove();" style="display: none;">
					    </div>
					</c:forEach>
					</c:if>
				 </div>
	        </div>
        </div>
      </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">联系方式:</label>
        <div class="col-md-9">
        	 <input id="mobile" value="${merchant.mobile}"  type="text" placeholder="联系方式" class="form-control" name="mobile"/>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">地址:</label>
        <div class="col-md-9">
        	 <input id="address" value="${merchant.address}"  type="text" placeholder="地址" class="form-control" name="address"/>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">商家简介:</label>
        <div class="col-md-9">
        	 <textarea id="description" value=""  type="text" placeholder="商家简介" class="form-control" name="description">${merchant.description}</textarea>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">特色优势:</label>
        <div class="col-md-9">
        	 <textarea id="advantage" value=""  type="text" placeholder="特色优势" class="form-control" name="advantage">${merchant.advantage}</textarea>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">企业类型:</label>
        <div class="col-md-9">
        	 <select id="typeId" data-placeholder="选择企业类型" class="chosen-select full-width"  tabindex="4">
			</select>
        </div>
    </div>
</div>

<script>
$(function(){
	jQuery.checkall(false);
})
var typeId="${merchant.typeId}";
$("#typeId").chosen({ width: '100%' });
$("#status").chosen({ width: '100%' });
$.ajax({  
	url:'${ctx}/merchantType/list',  		 					
	type: 'POST',
	dataType:'json',  
	success:function(response){
		if(response.code==0){
			var html=[];
			var data=response.data||[];
			for(var i=0;i<data.length;i++){
				html.push('<option value="'+data[i].id+'" ');
				if(typeId===data[i].id){
					html.push('selected="selected"'); 
				}
				html.push('>'+data[i].name+'</option>');
			}
			$("#typeId").append(html.join(""));
			$("#typeId").val(typeId);
			$("#typeId").trigger("chosen:updated");
		}
	}  
 });
$("#imageUploadify").uploadify({
	'buttonImage':'${ctx}/static/js/plugins/uploadify/uploadify-button.png',
    'swf': '${ctx}/static/js/plugins/uploadify/uploadify.swf',
    'uploader':'${ctx}/file/uploadOss',
    "multi":false,
    'onFallback' : function() {//检测FLASH失败调用 
    	alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");  
    },  
    'onUploadSuccess':function(file, data, response){
    	var jData = jQuery.parseJSON(data);
        $("#logodiv").html("<img src=\""+jData.data+"\" style=\"width: 60px;height: 60px;padding-left:5px;\">");
	}
});

$("#licenseUploadify").uploadify({
	'buttonImage':'${ctx}/static/js/plugins/uploadify/uploadify-button.png',
    'swf': '${ctx}/static/js/plugins/uploadify/uploadify.swf',
    'uploader':'${ctx}/file/uploadOss',
    "multi":false,
    'onFallback' : function() {//检测FLASH失败调用 
    	alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");  
    },  
    'onUploadSuccess':function(file, data, response){
    	var jData = jQuery.parseJSON(data);
        var html=" <div  style=\"width: 60px;float: left; margin-right: 5px;position: relative;\" class=\"twoimgs\"  onmouseout=\"javascript:$(this).find('.delimg').css('display','none')\" onmousemove=\"javascript:$(this).find('.delimg').css('display','block')\">";
            html+=" <img style=\" height: 60px; width: 60px; \" class=\"upimg\" src=\'"+jData.data+"'\">";
            html+="<img style=\"width: 60px;position: absolute;top: 42px;display:none\" class=\"delimg\" src=\"${ctx}/static/img/picdel.png\" onclick=\"javascript:$(this).parent().remove();\" style=\"display: none;\"></div>";

        $("#licensediv").append(html);
	}
});
</script>